from common import ReviewEntity,SongEntity, ParameterEntity 
from common import utility,SearchFilter
from dataaccess import AlbumData, ReviewData, SongData, ParameterData

def submit(albumEntity):
    """viewing and submitting an album review"""
    resp = dict()
    resp["album"] = albumEntity

    sf = SearchFilter.SimpleFilter(ParameterEntity.ParameterEntity.ColumnNames.paramType, SearchFilter.ConditionType.Equal, utility.ParameterGroup.Rotation)
    rotationRows = ParameterData.ParameterData().SelectParameterByFilter(sf)
    rotations = {}
    for parameterEntity in rotationRows:
        rotations[parameterEntity.ParamID] = parameterEntity.ParamName
    resp["rotations"] = rotations

    sf = SearchFilter.SimpleFilter(ParameterEntity.ParameterEntity.ColumnNames.paramType, SearchFilter.ConditionType.Equal, utility.ParameterGroup.Genre)
    genreRows = ParameterData.ParameterData().SelectParameterByFilter(sf)
    genres = {}
    for parameterEntity in genreRows:
        genres[parameterEntity.ParamID] = parameterEntity.ParamName
    resp["genres"] = genres

    return resp

def index(submitted_review):
    """TODO: get real reviews from db"""
    resp = dict()

    messages = dict()
    messages['submitted_review'] = submitted_review

    reviews = AlbumData.AlbumData().SelectAlbumsForReview()
    resp['reviews'] = reviews 
    resp['messages'] = messages
    return resp

def approve(album_id):
    """review an album with director privileges"""
    #TODO:give correct permissions
    return submit(album_id)

def admin():
    """view all the reviewable albums with director privileges"""
    #TODO:give correct permissions
    return index(False) 

